package ESP.Util;

public class Page {
	private static int maxCount = 10;// 一页多少条
	private int totalCount;// 总条数
	private int pageCount;// 总页数
	private int curPage = 1;// 当前页数
	private int startPosition;// 开始取数据的位置

	// 跳转到多少页
	public void setCurPage(int curPage) {
		this.curPage = curPage;
		// 考虑到页数小于第一页和页数大于最后一页
		if (curPage < 1) {
			curPage = 1;
		} else if (curPage > pageCount) {
			curPage = pageCount;
		}
		this.startPosition = (curPage - 1) * maxCount;
	}

	// 导入总记录数
	public void setTotalCount(int totalCount) {
		// 将其他属性的值计算出来
		// 计算总页数
		pageCount = totalCount / maxCount;
		if (totalCount % maxCount != 0) {
			pageCount++;
		}

		// 当前位置
		startPosition = (curPage - 1) * maxCount;

		this.totalCount = totalCount;
	}

	/**
	 * 首页
	 */
	public void firstPage() {
		this.curPage = 1;
		this.startPosition = (curPage - 1) * maxCount;
	}

	/**
	 * 尾页
	 */
	public void lastPage() {
		this.curPage = this.pageCount;
		this.startPosition = (curPage - 1) * maxCount;
	}

	/**
	 * 下一页
	 */
	public void nextPage() {
		this.curPage = this.curPage + 1;
		// 如果超过总页数，那么就是最后一页
		if (this.curPage > this.pageCount) {
			this.curPage = this.pageCount;
		}
		this.startPosition = (curPage - 1) * maxCount;
	}

	/**
	 * 上一页
	 */
	public void previousPage() {
		this.curPage = this.curPage - 1;
		// 如果上一页页数小于第一页，那么就是第一页
		if (this.curPage < 1) {
			this.curPage = 1;
		}
		this.startPosition = (curPage - 1) * maxCount;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getStartPosition() {
		return startPosition;
	}

	public void setStartPosition(int startPosition) {
		this.startPosition = startPosition;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public int getCurPage() {
		return curPage;
	}

	public static int getMaxCount() {
		return maxCount;
	}

	public static void setMaxCount(int maxCount) {
		Page.maxCount = maxCount;
	}

}
